Imports Microsoft.Win32
Friend Class libRegistry

    Dim r_sectionKey As String
    Friend WriteOnly Property sectionKey() As String
        Set(ByVal Value As String)
            r_sectionKey = Value
        End Set
    End Property

    Dim r_valueKey As String
    Friend WriteOnly Property valueKey() As String
        Set(ByVal Value As String)
            r_valueKey = Value
        End Set
    End Property

    Dim r_defaultValue As Object
    Friend WriteOnly Property defaultValue() As Object
        Set(ByVal Value As Object)
            r_defaultValue = Value
        End Set
    End Property

    Public Property value() As Object
        Get
            Dim regKey As RegistryKey
            Dim vValue As Object
            regKey = Registry.LocalMachine.OpenSubKey(r_sectionKey, False)
            If regKey Is Nothing Then
                createSubKey()
                regKey = Registry.LocalMachine.OpenSubKey(r_sectionKey, False)
            End If
            vValue = regKey.GetValue(r_valueKey, r_defaultValue)
            regKey.Close()
            Return vValue
        End Get
        Set(ByVal Value As Object)
            Dim regKey As RegistryKey
            regKey = Registry.LocalMachine.OpenSubKey(r_sectionKey, True)
            If regKey Is Nothing Then
                createSubKey()
                regKey = Registry.LocalMachine.OpenSubKey(r_sectionKey, True)
            End If
            regKey.SetValue(r_valueKey, Value)
            regKey.Close()
        End Set
    End Property

    Friend Sub deleteValue()
        Dim regKey As RegistryKey
        regKey = Registry.LocalMachine.OpenSubKey(r_sectionKey, True)
        If Not regKey Is Nothing Then
            regKey.DeleteValue(r_valueKey)
            regKey.Close()
        End If
    End Sub

    Private Sub createSubKey()
        Dim regkey As RegistryKey
        regkey = Registry.LocalMachine.CreateSubKey(r_sectionKey)
        regkey.Close()
    End Sub

End Class
